package com.xhh.reapply.listener;

import com.xhh.common.constants.ReapplyConstants;
import com.xhh.model.reapply.pojos.Preapply;
import com.xhh.model.reapply.pojos.Reapply;
import com.xhh.reapply.service.IPreapplyService;
import com.xhh.reapply.service.ReapplyService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RequiredArgsConstructor
public class DelPreapplyListener {

    private final IPreapplyService preapplyService;

    @RabbitListener(bindings = @QueueBinding(
        value = @Queue(value = ReapplyConstants.QUEUE_NAME_DELETE, durable = "true"),
        exchange = @Exchange(ReapplyConstants.EXCHANGE_NAME),
        key = ReapplyConstants.DELETE_PREAPPLY_KEY
    ))
    public void listenDelPreapply(Long id){
        log.info("复试备选库id：{}", id);
        // 1. 获取复试备选志愿
        Preapply preapply = preapplyService.getById(id);
        // 2.幂等判断，判断志愿是否存在
        if (preapply == null) {
            return;
        }
        // 3.删除
        preapplyService.removeById(id);
    }
}
